package com.ruoyi.web.controller.combat.userlocation;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.combat.domain.userlocation.CombatWarn;
import com.ruoyi.combat.service.userlocation.ICombatWarnService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 告警信息Controller
 *
 * @author ruoyi
 * @date 2024-08-30
 */
@Api(tags = "课题三：网络抗定位-告警信息管理")
@RestController
@RequestMapping("/userlocation/warn")
public class CombatWarnController extends BaseController {
    @Autowired
    private ICombatWarnService combatWarnService;

    /**
     * 查询告警信息列表
     */
    @ApiOperation(value = "查询告警信息列表")
    @PreAuthorize("@ss.hasPermi('system:warn:list')")
    @GetMapping("/list")
    public TableDataInfo list(CombatWarn combatWarn) {
        startPage();
        List<CombatWarn> list = combatWarnService.selectCombatWarnList(combatWarn);
        return getDataTable(list);
    }

    /**
     * 导出告警信息列表
     */
    @ApiOperation(value = "导出告警信息列表")
    @PreAuthorize("@ss.hasPermi('system:warn:export')")
    @Log(title = "告警信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CombatWarn combatWarn) {
        List<CombatWarn> list = combatWarnService.selectCombatWarnList(combatWarn);
        ExcelUtil<CombatWarn> util = new ExcelUtil<CombatWarn>(CombatWarn.class);
        util.exportExcel(response, list, "告警信息数据");
    }

    /**
     * 获取告警信息详细信息
     */
    @ApiOperation(value = "获取告警信息详细信息")
    @PreAuthorize("@ss.hasPermi('system:warn:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(combatWarnService.selectCombatWarnById(id));
    }

    /**
     * 新增告警信息
     */
    @ApiOperation(value = "新增告警信息")
    @PreAuthorize("@ss.hasPermi('system:warn:add')")
    @Log(title = "告警信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CombatWarn combatWarn) {
        return toAjax(combatWarnService.insertCombatWarn(combatWarn));
    }

    /**
     * 修改告警信息
     */
    @ApiOperation(value = "修改告警信息")
    @PreAuthorize("@ss.hasPermi('system:warn:edit')")
    @Log(title = "告警信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CombatWarn combatWarn) {
        return toAjax(combatWarnService.updateCombatWarn(combatWarn));
    }

    /**
     * 删除告警信息
     */
    @ApiOperation(value = "删除告警信息")
    @PreAuthorize("@ss.hasPermi('system:warn:remove')")
    @Log(title = "告警信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(combatWarnService.deleteCombatWarnByIds(ids));
    }

    /**
     * 按照地区统计警告信息
     */
    @ApiOperation(value = "按照地区统计警告信息")
    @PreAuthorize("@ss.hasPermi('system:warn:list')")
    @GetMapping("/area")
    public AjaxResult getAreaByProvince() {
        return success(combatWarnService.getAreaByProvince());
    }

    /**
     * 按照泄露地点统计告警信息
     */
    @ApiOperation(value = "按照地区统计警告信息")
    @PreAuthorize("@ss.hasPermi('system:warn:list')")
    @GetMapping("/leak")
    public AjaxResult getPostionsByWarn() {
        return success(combatWarnService.getPostionsByWarn());
    }
}
